package com.yy.wga.goods.service.controller;


import com.yy.wga.module.goods.request.*;
import com.yy.wga.module.goods.response.*;
import com.yy.wga.mp.common.aop.NotLogin;
import com.yy.wga.mp.module.goods.common.enums.ECategory;
import com.yy.wga.mp.module.goods.manager.ProductManager;
import com.yy.wga.mp.module.goods.request.GetCategoryGoodsReq;
import com.yy.wga.mp.module.goods.request.GetSpuListReq;
import com.yy.wga.mp.module.goods.request.GoodsTransferReq;
import com.yy.wga.mp.module.goods.response.GoodSpuListResp;
import com.yy.wga.mp.module.goods.response.GoodsInfoResp;
import com.yy.wga.mp.module.goods.response.GoodsProductPromotionLinkResp;
import com.yy.wga.mp.module.goods.response.GoodsShareResp;
import com.yy.wga.mp.module.resource.manage.ResourceGoodsCategoryManager;
import com.yy.wga.mp.module.resource.response.GetResourceGoodsCategoryResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 商品管理
 *
 * @author guochao
 * @since 2024-10-25 21:46:26
 */
@RestController
@RequestMapping("api/goods")
@Api(tags = "商品管理")
public class GoodsController {
    /**
     * 服务对象
     */
    @Resource
    private ProductManager productManager;
    @Resource
    private ResourceGoodsCategoryManager resourceGoodsCategoryManager;


    /**
     * 商品列表
     *
     * @return
     */
    @ApiOperation(value = "获取分类列表")
    @GetMapping("getCategoryMap")
    @NotLogin
    public Result<Map<String, Integer>> getCategoryMap() {
        Map<String, Integer> categoryTypeNameMap = ECategory.getCategoryTypeNameMap();
        return Result.success(categoryTypeNameMap);
    }

    /**
     * 商品列表
     *
     * @return
     */
    @ApiOperation(value = "商品列表")
    @PostMapping("list")
    public Result<GoodSpuListResp> list(@RequestBody @Valid GetSpuListReq request) {
        GoodSpuListResp goodSpuListResp = productManager.getSpuList(request);
        return Result.success(goodSpuListResp);
    }

    // TODO 增加合作商品分类
    // TODO 增加合作商品商品详情


    @ApiOperation(value = "分享商品")
    @PostMapping("share")
    public Result<GoodsShareResp> share(@RequestBody @Valid GoodsTransferReq request) {
        return Result.success(productManager.share(request));
    }

    @GetMapping(value = "getCategory")
    @ApiOperation(value = "获取品类")
    public Result<List<GetResourceGoodsCategoryResponse>> listCategory() {
        List<GetResourceGoodsCategoryResponse> list = resourceGoodsCategoryManager.listAvailableCategory();
        Result<List<GetResourceGoodsCategoryResponse>> result = Result.success();
        result.setData(list);
        return result;
    }

    @ApiOperation(value = "获取品类下的推客商品")
    @PostMapping("getCategoryGoods")
    public Result<PageBean<GoodsInfoResp>> getCategoryGoods(@RequestBody @Valid GetCategoryGoodsReq request) {
        return Result.success(productManager.getCategoryGoods(request));
    }

    @ApiOperation(value = "商品转链")
    @PostMapping("getProductPromotionLink")
    public Result<GoodsProductPromotionLinkResp> getProductPromotionLink(@RequestBody @Valid GoodsTransferReq request) {
        return Result.success(productManager.getProductPromotionLink(request));
    }


//    @ApiOperation(value = "同步商品")
//    @GetMapping("syncGoods")
//    @NotLogin
//    public Result<Void> syncGoods() {
//        productManager.syncGoods();
//        return Result.success();
//    }
}
